package kin.bean.security;


import java.util.List;




import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;




@Entity
@Table(name="t_module")
@JsonInclude(Include.NON_NULL)

@JsonIgnoreProperties(ignoreUnknown=true)
//@JsonWriteNullProperties
// @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Module {
	/*
	 * 模块编号,是唯一的,如:org,system,info
	 */
	
	@Column(/*nullable = true*/)
	private boolean leaf;
	@Column
    private String classMethodName;
	@Column
	private String className;
	@Column
	private boolean renderToNAV;
	@Column
	private String simpleClassName;
	@Column
	private String view;
	
	
	
	public boolean isRenderToNAV() {
		return renderToNAV;
	}

	public void setRenderToNAV(boolean renderToNAV) {
		this.renderToNAV = renderToNAV;
	}

	

	

	@Id
	@GeneratedValue
	
	private int module_id;

	@Column(length = 30, nullable = false)
	
	private String label;

	@Column(length = 60, nullable = false, name = "module_url")
	private String module_url;

	@Column()
	
	private int module_orderNo;
	
	@Column
	
	private String method;
	
	

	@ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.EAGER)
	private Module parent;

	@OneToMany(cascade = { CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.EAGER, mappedBy = "parent")
	private List<Module> children ;
    
	public boolean isLeaf() {
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}

	
   
	
	
	
	



	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public List<Module> getChildren() {
		return children;
	}

	public void setChildren(List<Module> children) {
		this.children = children;
	}

	public int getModule_id() {
		return module_id;
	}

	public void setModule_id(int module_id) {
		this.module_id = module_id;
	}

	public String getModule_url() {
		return module_url;
	}

	public void setModule_url(String module_url) {
		this.module_url = module_url;
	}

	public int getModule_orderNo() {
		return module_orderNo;
	}

	public void setModule_orderNo(int module_orderNo) {
		this.module_orderNo = module_orderNo;
	}
	
@JsonIgnore
	public Module getParent() {
		return parent;
	}

	public void setParent(Module parent) {
		this.parent = parent;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	

	public String getClassMethodName() {
		return classMethodName;
	}

	public void setClassMethodName(String classMethodName) {
		this.classMethodName = classMethodName;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	
	public String getSimpleClassName() {
		return simpleClassName;
	}

	public void setSimpleClassName(String simpleClassName) {
		this.simpleClassName = simpleClassName;
	}

	public String getView() {
		return view;
	}

	public void setView(String view) {
		this.view = view;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((classMethodName == null) ? 0 : classMethodName.hashCode());
		result = prime * result
				+ ((className == null) ? 0 : className.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Module other = (Module) obj;
		if (classMethodName == null) {
			if (other.classMethodName != null)
				return false;
		} else if (!classMethodName.equals(other.classMethodName))
			return false;
		if (className == null) {
			if (other.className != null)
				return false;
		} else if (!className.equals(other.className))
			return false;
		return true;
	}

	

	
	
	

	
}
